Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Use .replace() with "

I am currently working on getting data from an API, and I want to remove some characters from what it returns.

What I get back is {"usd":323.67}, but the currency and price may change depending on the input.

I want to remove the {}, usd (or other currency), "" and :. I searched, and found .replace() could be a good solution, if you replace the character with nothing. But when I use .replace(""", "");, I of course get an error. When I do, .replace("{}", "");, it doesn't replace the {} with nothing either. And because I use a constant for the currency, because the user can choose, the currency it not always the same, so I thought it could use .replace(${currency}`, ""), but that also doesn't work.

What should I do to remove these things from my string?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As others commented, parse your data as JSON and then get the value using your currency variable, something like this (not sure about what framework you are using, so the currency replacement may vary from what's shown here):

data = {"usd":323.67};
value = data.${currency};
about 4 years ago · Juan Pablo Isaza Relatório

0

You have to find all numbers in string and then concat them with '.' symbol

const getValue = (str) => str.match(/\d+/g).join('.')
console.log(getValue('{"usd":323.67}'))
console.log(getValue('{"rub":323,67p}'))
console.log(getValue('"euro":333-00'))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda